$(document).ready(function(){
	var imagefilename = '';
	$('#imagefile').bind('change',function(){
		var form = new FormData();
		form.append('imagefile',$('#imagefile')[0].files[0]);
		var req = new XMLHttpRequest();
		req.open("POST", "ajax_upload_project_image");
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
					var json = JSON.parse(req.responseText);
					if(json.type==0){
						$('#showimage').attr('src','files/image/'+json.filename);
						imagefilename = json.filename;
					}
				}
			}
		}
		req.send(form);
	});
	$('#zipFile').bind('change',function(){
		var form = new FormData();
		form.append('zipFile',$('#zipFile')[0].files[0]);
		var req = new XMLHttpRequest();
		req.open("POST", "ajax_upload_project_zip_file");
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
					var json = JSON.parse(req.responseText);
					if(json.type==0){
						$('#fileSum').text('文件数量：'+json.fileSum);
						$('#iframe_url').val(json.dirName);
					}
				}
			}
		}
		req.send(form);
	});
	$('#create').bind('click',function(){
		$.post('ajax_create_project',{
			'isoriginal':$('#type').val(),
			'columns_id':$('#colum').val(),
			'title':$('#title').val(),
			'image_filename':imagefilename,
			'context':$('#context').val(),
			'isoriginal':$('#type').val(),
			'iframe_url':$('#iframe_url').val(),
			'original_url':$('#original_url').val(),
			'isCreateApp':$('#isCreateApp').val()
		},function(data,status){
			if(status=='success'){
				if(data.type==0){
					location.href = '/';
				}else{
					alert(data.msg);
				}
			}else{
				alert('未知错误');
			}
		});
	});
});